/**
 * 从本地拷贝文件到hdfs 打印拷贝进行
 */
package net.zwj.hadoop.dfs;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Progressable;

/**
 * @author zhouwj
 * 
 */
public class FileCopyWithProgress {

	public static void main(String[] args) throws IOException, InterruptedException {
		String localSrc = args[0];
		String dst = args[1];
//		String localSrc = "E:/serial.txt";
//		String dst = "hdfs://192.168.100.45:9000/test/z.txt";
		
		InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
		Configuration conf = new Configuration();		
		FileSystem fs = FileSystem.get(URI.create(dst), conf);
		OutputStream out = fs.create(new Path(dst),new Progressable() {
			
			@Override
			public void progress() {
				System.out.print(".");
			}
		});
		IOUtils.copyBytes(in, out, 4096,true);
		
		
	}

}
